<?php

// 检测项目是否满足一键融资条件
// GET project.checkComplete

namespace app\api\resource\project;
use think\Db;

class CheckComplete
{
    // 方法
    public $_method = ['GET'];
    // 前置
    public $_pre    = ['login','isCyz'];
    // 描述
    public $_description = '检测项目是否满足一键融资条件';
    // 参数
    public $_param  = [
        'project_id' => '项目主键',
    ];
    // 返回
    public $_return = [
        200 => '检测成功,返回检测结果,ret:检测结果,msg:未完善项',
        400 => '项目不存在',
        422 => '项目主键必须',
    ];

    public function run(&$request)
    {
        $projectId = $request->get('project_id/d',0);

        if (0 == $projectId) return [422,'项目主键必须'];

        $project = Db::name('project')->where('id',$projectId)->find();
        if ( is_null($project) ) return [400,'项目不存在'];

        // 检查项目是否完善项目
        $arr = [
            'team'    => [
                'ret' => false,
                'msg' => '团队规模',
            ],
            'members'    => [
                'ret' => false,
                'msg' => '团队成员',
            ],
            'bp'    => [
                'ret' => false,
                'msg' => '商业计划书',
            ],
        ];

        $arr['team']['ret']    = empty($project['team']) ? false : true;
        $arr['members']['ret'] = ( empty($project['members']) || '[]' == $project['members'] ) ? false : true;
        $arr['bp']['ret']      = empty($project['bp']) ? false : true;

        $temp = [];
        foreach ($arr as $key => $val) {
            if (!$val['ret']) $temp[] = $val['msg'];
        }

        if ( empty($temp) ) {
            $res = ['ret'=>true];
        } else {
            $res = ['ret'=>false,'msg'=>$temp];
        }

        return [200,$res];
    }
}
